import http from './http';

// 获取购物车
export const getCart = async () => {
  try {
    const response = await http.get('/cart');
    return response;
  } catch (error) {
    return error;
  }
};

// 添加商品到购物车
export const addToCart = async (bookId, quantity) => {
  try {
    const response = await http.post('/cart', { bookId, quantity });
    return response;
  } catch (error) {
    return error;
  }
};

// 更新购物车商品数量
export const updateCartItem = async (bookId, quantity) => {
  try {
    const response = await http.put(`/cart/${bookId}?quantity=${quantity}`);
    return response;
  } catch (error) {
    return error;
  }
};

// 从购物车移除商品
export const removeFromCart = async (bookId) => {
  try {
    const response = await http.delete(`/cart/${bookId}`);
    return response;
  } catch (error) {
    return error;
  }
};

// 清空购物车
export const clearCart = async () => {
  try {
    const response = await http.delete('/cart');
    return response;
  } catch (error) {
    return error;
  }
}; 